package com.liruo.treasureattic.starter.oss.model.future;

import com.qcloud.cos.model.UploadResult;
import com.qcloud.cos.transfer.Upload;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @Author:liruo
 * @Date:2023-02-18-12:10:54
 * @Desc
 */
public class UploadFuture implements Future<Boolean>{
    private Upload upload;

    public UploadFuture(Upload upload) {
        this.upload = upload;
    }

    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        this.upload.abort();
        return false;
    }

    @Override
    public boolean isCancelled() {
        return false;
    }

    @Override
    public boolean isDone() {
        return this.upload.isDone();
    }

    @Override
    public Boolean get() throws InterruptedException{
        UploadResult uploadResult = this.upload.waitForUploadResult();
        return uploadResult != null;
    }

    @Override
    public Boolean get(long timeout, TimeUnit unit){
        return null;
    }
}
